<template>
    <div id="box">
        <div id="layer" v-show="showLayer">请选择出行国家</div>
        <div id="search">
            <span @click="back" slot="left"><img src="static/icons/blueB.png" id="back"></span>
            <input type="text" v-model="countryName" @keydown.enter="searchCountry">
            <img src="static/icons/search.png" class="img-size" @click="searchClick">
        </div>
        <div id="search-box">
            <!--目的地-->
            <div id="country-box" >
                <div class="left">
                    <p class="country-item" @click="couClick">{{country[0].type}}</p>
                    <p class="country-start" @click="citClick">{{startCity[0].startCity}}</p>
                </div>
                <!--目的地信息-->
                <div id="right-content" v-show="showInfo">   
                    <div class="right" v-for="i in country[0].countries">    
                        <div>
                            <p class="country-title">{{i.region}}</p>
                        </div>
                        <div class="allcity">
                            <div class="right-box" v-for="j in i.cicties">
                                <label for="">{{j}}</label>
                            </div>
                        </div>  
                    </div>
                </div>
                <!--出发城市信息-->
                <div id="start" v-show="showcity">
                    <div class="allcity">
                        <div class="right-box" v-for="a in startCity[0].countries">
                            <!--<input type="checkbox">-->
                            <label for="">{{a}}</label>
                        </div>
                    </div>
                </div>
            </div>   
        </div>
    </div>
</template>

<script>
import Navbar from '../components/Navbar.vue';
import {mapState} from "vuex";
export default {
    data:function(){
        return{
        showCountry:true,
        showcity:false,
        showInfo:true,
        countryName:"",
        timer:null,
        showLayer:false
        }
    },
    components:{
        Navbar
    },
    methods:{
        back(){
            history.back();
        },
        // 点击目的地
        couClick(){
            this.showcity=false;
            this.showInfo=true;
            var countryItem =document.getElementsByClassName("country-item")[0];
            var countryStart =document.getElementsByClassName("country-start")[0];
            if(this.showCountry){
                countryItem.style="background-color:#fff;color:#036ab5";
                countryStart.style="background-color:#f4f4f4;color:#777";
            }
        },
        // 点击出发地
        citClick(){
            this.showInfo=false;
            var countryStart =document.getElementsByClassName("country-start")[0];
            var countryItem =document.getElementsByClassName("country-item")[0];
            this.showcity=true;
            if(this.showcity){
                countryItem.style="background-color:#f4f4f4;color:#777";
                countryStart.style="background-color:#fff;color:#036ab5";
            }
        },
        searchCountry(e){
            if(this.countryName){
                this.$store.dispatch("reqestCountryTrip",this.countryName)
                .then(data=>{
                    this.$router.push({path:"/searchTrip"})
                }) 
            }else{
                this.showLayer=true;
               setTimeout(function() {
                  this.showLayer=false; 
               }.bind(this), 700);
            }
        },
        searchClick(){
            if(this.countryName){
                this.$store.dispatch("reqestCountryTrip",this.countryName)
                .then(data=>{
                    this.$router.push({path:"/searchTrip"})
                }) 
            }else{
               this.showLayer=true;
               setTimeout(function() {
                  this.showLayer=false; 
               }.bind(this), 700);
            }
        
        }
    },
    computed:{
        ...mapState([
            "country","startCity"
        ])
    },
    mounted:function(){
        this.$store.dispatch("requestStartCity");
        this.$store.dispatch("requestCountry");
    }
}
</script>

<style lang='css' scoped>
    #back{
        width:30px;
        height:30px;
        /*border: 1px solid  red;*/
        
    }
    #box{
        position: relative;
    }
    #search-box{
        height: calc(100vh - 53px);
        overflow: hidden;
    }
    .img-size{
        width: 28px;
        height: 28px;
        /*border: 1px solid  red;*/
    }
    #search>input{
        width: 68vw;
        height: 35px;
        border: 1px  solid #e6e6e8;
        border-radius: 5px;
    }
    #search{
        background-color: #f8f8f8;
        /*border: 1px solid  red;*/
        display: flex;
        justify-content: space-between;
        height: 53px;
        width: 100vw;
        line-height: 53px;
        padding:0 10px;
        padding-top: 8px;
    }
    .nav-size{
        line-height:40px;
        font-size: 18px;
        color: #0894EC;
    }
    #search input{
         line-height:40px;
         padding-left: 10px;
    }
    #country-box{
        display: flex;
        color: #777;
    }
    .left{
        width: 30vw;
        background-color: #f4f4f4;
        padding-top: 53px;
        height: 100vh;
        font-size: 14px;
    }
    .left>p{
        /*border: 1px solid red;*/
        margin:0px;
        display: inline-block;
        height: 60px;
        width: 100px;
        line-height: 60px;
        text-align: center;
    }
    .left P:nth-of-type(1){
        background-color: #fff;
        color:#036ab5;
    }
    #right-content{
        height: calc(100vh - 53px);
        overflow: scroll;
        /*border: 1px solid red;*/
        padding-left: 10px;
    }
    .right{
       background-color: #fff;
    }
    .allcity{
        /*border: 1px solid red;*/
        display: flex;
        flex-wrap: wrap;
    }
    .right-box{
        width: 70px;
        height: 40px;
        line-height: 40px;
        font-size: 13px;
        margin-right: 10px;
        /*border: 1px solid red;*/
        text-align: center;
    }
    .country-title{
        font-size: 15px;
        margin: 0;
        display: inline-block;
        height: 30px;
        color: #036ab5;
        /*border: 1px solid red;*/
        line-height: 30px;
    }
    #start{
        display: flex;
        height: calc(100vh - 53px);
        overflow: scroll;
    }
    #layer{
        width: 120px;
        height: 50px;
        background-color: rgba(0, 0, 0, 0.7);
        color: #fff;
        line-height: 50px;
        font-size: 14px;
        text-align: center;
        position: absolute;
        top: 100px;
        left: 30vw;
        border-radius: 5px;

    }


</style>